package org.west.sky.frame.activiti.study.chapter14;

import lombok.SneakyThrows;
import org.activiti.engine.history.HistoricVariableInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.west.sky.frame.activiti.study.chapter14.demo0102.Calculation;
import org.west.sky.frame.activiti.study.util.ActivitiEngineUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * author: chz
 * date: 2025/3/12
 * description: 服务任务-异常处理
 */
public class RunDemo14_1_4 extends ActivitiEngineUtil {

    public static void main(String[] args) {
        RunDemo14_1_4 runDemo13_1_1 = new RunDemo14_1_4();
        runDemo13_1_1.deploy();
    }

    @SneakyThrows
    private void deploy() {
        loadActivitiConfigAndInitEngine("activiti.cfg.xml");
        //部署流程
        ProcessDefinition processDefinition = deployByClassPathResource("processes/chapter14/Chapter14_1_4.bpmn20.xml");

        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());

        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task.getName() + "：任务节点");
        Map<String, Object> variables = new HashMap<>();
        variables.put("inventory", 4);
        variables.put("description", "校验物资领取的数量是否大于库存数量");
        taskService.complete(task.getId(), variables);

        Task task2 = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
        System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task2.getName() + "：任务节点");
        taskService.complete(task2.getId());

        closeEngine();
    }


}
